/**
 * Copyright (c) 2007, Blue Hole Software. All rights reserved.
 * Code licensed under the Apache 2.0 License:
 * http://www.apache.org/licenses/
 */
package org.bhf.json;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.GenericSignatureFormatError;
import java.lang.reflect.Method;

/**
 * Do not write properties tagged with <code>JSONTransient</code>.
 * @see JSONWriter
 */
@Documented
@Retention( RetentionPolicy.RUNTIME )
@Target( ElementType.METHOD )
public @interface JSONTransient
{
    /**
     * Utility accessors for <code>JSONConfig</code>
     * @exclude
     */
    public static final class Util
    {
        static final Class<JSONTransient> clazz = JSONTransient.class;

        /**
         * Obtain the <code>JSONConfig</code> annotation for the specified POJO/JavaBean property.
         * @param getter Getter method representing a property.
         * @return the <code>JSONConfig</code> annotation for the specified POJO/JavaBean property
         *      if it exists; otherwise <code>null</code>.
         */
        public static boolean isTransient( final Method getter )
        {
            try
            {
                return getter != null && getter.getAnnotation( clazz ) != null;
            }
            catch( GenericSignatureFormatError gsfe ) // JDK Bug
            {
                return false;
            }
        }
    }
}
